import Vue from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import store from './store'
import rem from './utils/rem'
/* 二次封装 */
import axios from './utils/http'
// import axios from 'axios'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import echarts from 'echarts'

// import VueSocketIo from 'vue-socket.io'
Vue.config.productionTip = false

axios.defaults.baseURL = '/api';
Vue.prototype.axios = axios;
Vue.prototype.$echarts = echarts
Vue.use(ElementUI);

// Vue.use(new VueSocketIo({
//   debug: true,

//   connection: 'http://172.16.10.201:8888', //这是路径比如：http://192.168.1.178

//   vuex: {},
// }))

//===============权限
router.beforeEach((to, from, next) => {
  //判断该页面是否需要登录
  if (to.meta.isLogin) {
    //需要登录就判断是否登录
    if (store.state.msgCount.user.user_name) {
      // console.log('登录了')
      //登录了过后就判断该用户有没有进入该页面的权限
      //管理员和超级管理员
      if (store.state.msgCount.user.role_id === 1 || store.state.msgCount.user.role_id === 2) {
        if (store.state.msgCount.user.menu.includes(to.meta.roles) || to.meta.roles === '') {
          next()
        } else {
          alert('你没有进入该页面的权限')
        }
      } else if (store.state.msgCount.user.role_id === 3) {
        // console.log('司机端')
        if (to.meta.roles === '司机端') {
          next()
        } else {
          alert('你没有进入该页面的权限')
        }
      } else if (store.state.msgCount.user.role_id === 4) {
        // console.log('用户端')
        if (to.meta.roles === '用户端') {
          next()
        } else {
          alert('你没有进入该页面的权限')
        }
      }
    } else {
      // console.log('还没登录，请先登录')
      alert('还没登录，请先登录')
      router.push('/login')
    }
  } else {
    next()
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')